package com.core
{
	import com.event.GameEvent;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	/**
	 * 基础视图类
	 * 底图和按钮
	 * 
	 * 各状态视图   无game视图
	 * 
	 * 算是最高层的视图
	 * ui其次
	 * game层
	 * 
	 **/
	public class BasicScreen extends MovieClip
	{
		public function BasicScreen()
		{
			super();
		}
		
		public function createTitleView($view:Class):void{
			var view:* = new $view
			addChild(view);
			view.start_btn.addEventListener(MouseEvent.CLICK,onStartClick);
			view.instruction_btn.addEventListener(MouseEvent.CLICK,onInstructionClick);
		}
		private function onStartClick(e:MouseEvent):void{
			dispatchEvent(new GameEvent(GameEvent.GAME_TITLE_TO_NEW_GAME_EVENT));
		}
		private function onInstructionClick(e:MouseEvent):void{
			dispatchEvent(new GameEvent(GameEvent.GAME_TITLE_TO_INSTRUCTION_EVENT));
		}
		
		public function createInstructionView($view:Class):void{
			var view:* = new $view;
			addChild(view);
			view.back_btn.addEventListener(MouseEvent.CLICK,onBackClick);
		}
		private function onBackClick(e:MouseEvent):void{
			dispatchEvent(new GameEvent(GameEvent.GAME_INSTRUCTION_TO_TITLE_EVENT));
		}
		
		public function createLevelIn($view:Class):void{
			var view:* = new $view;
			addChild(view);
		}
		
		private var _view:*
		public function createLevelSelect(p_view:Class):void{
			_view = new p_view;
			addChild(_view);
			_view.addEventListener(GameEvent.GAME_LEVEL_SELECT,onGameLevelSelect)
		}
		private function onGameLevelSelect(e:GameEvent):void{
			trace("=====level"+e.level)
			var evt:GameEvent = new GameEvent(GameEvent.GAME_LEVEL_SELECT);
			evt.level = e.level;
			dispatchEvent(evt);
		}
		public function showLevel(p_level:int):void{
//			_view.showLevel(p_level)
		}
		
		
		public function createGameOverView($view:Class):void{
			var view:* = new $view;
			addChild(view);
			view.replay_btn.addEventListener(MouseEvent.CLICK,onReplayClick);
		}
		private function onReplayClick(e:MouseEvent):void{
			dispatchEvent(new GameEvent(GameEvent.GAME_OVER_TO_TITLE_EVENT));
		}
	}
}